﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ChinessChess
{
    public partial class Frmregister : Form
    {
        public Frmregister()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            DataChessDataContext db = new DataChessDataContext();
            var query = from p in db.tblRegisters where p.username==txtUser.Text
                        select p;

            if (query.Count<tblRegister>() > 0)
            {
                MessageBox.Show("User nay da dang ky roi vui long nhap vao user khac");
                txtUser.Text = "";
                txtUser.Focus();
                return;
            }
            if (txtPass.Text != txtRePass.Text)
            {
                MessageBox.Show("Vui long nhap lai mat khau.!!!");
                return;
            }
            tblRegister register = new tblRegister();
            register.username = txtUser.Text;
            register.pass = txtPass.Text;
            register.fullname = txtFullName.Text;
            register.email = txtEmail.Text;
            register.active = true;
            register.birthday = dttBirthday.Value;
            db.tblRegisters.InsertOnSubmit(register);
            db.SubmitChanges();
            MessageBox.Show("Ban dang ky thanh cong!!!");
            this.Close();
            frmLogIn f = new frmLogIn();
            f.Show();
        }


    }
}
